home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / FDDISP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  2.6 KB  |  95 lines

  1. /* fddisp.c file - display_page: display current page of file    */
  2. #include "stdio.h"
  3. #include "cminor.h"
  4. #include "fdparm.h"
  5.  
  6. extern    char  filename[] ;
  7. extern    long  filesize     ;        /* size of file in bytes */
  8. extern    long  top_of_page ;        /* file position of top of page */
  9.  
  10. /* special symbols to represent CR, LF, CTL-Z, & other ctl chars */
  11. #define PRT_CR     20
  12. #define PRT_LF     25
  13. #define PRT_CTLZ 17
  14. #define PRT_OTHER 22
  15. #define ASC_CTLZ 26
  16.  
  17. int  row ;                /* current line of page */
  18. long start ;
  19.  
  20.  
  21. int display_page()
  22.   {
  23.      char block[ LINE_SIZE ] ;
  24.      int   nbytes ;
  25.      int   i  ;             /* index for loops */
  26.  
  27.      move_to(top_of_page) ;        /* start at top of the page */
  28.                     /* write a header line */
  29.      printf("\n FILE - %s    POSITION - %1d    FILE SIZE - %1d \n",
  30.      filename, top_of_page, filesize) ;
  31.      for( i=1 ; i < 80 ; i = i+1 ) /* write a border ilne of dashes */
  32.     {  putchar('-') ; }
  33.  
  34.      /* get chars from file until we've written (PAGE_SIZE) lines */
  35.      /* or we've reached the end of the file  */
  36.      row = 1 ;                /* starting row values    */
  37.      start = top_of_page ;
  38.      while( row <= PAGE_SIZE )
  39.     {  nbytes = read_line(block,LINE_SIZE)    ;
  40.        if( nbytes <= 0 )
  41.           break ;
  42.        prtline(block,nbytes) ;
  43.        start = start + nbytes ;
  44.        row = row + 1 ;
  45.     }
  46.  
  47.      while( row <= PAGE_SIZE )        /* pad out page if eof reached */
  48.     {  putchar('\n') ; row = row + 1 ; }
  49.      for( i=1 ; i <= 80 ; i = i+1 )    /* write border line of dashes */
  50.     {  putchar('-') ; }
  51.   }
  52.  
  53.  
  54. int prtline(block,nbytes)        /* prints one line */
  55.   char    block[]  ;
  56.   int    nbytes    ;
  57.   {
  58.      int i ;
  59.  
  60.      printf("%81d  | ",start)  ;        /* print file pos  */
  61.      for( i=1 ; i < LINE_SIZE ; i = i+1)/* print bytes in hex */
  62.     {  if ( i < nbytes )
  63.         printf("%02x ",( tochar(block[i]) ) ) ;
  64.        else printf("   ") ;         /* out of data - fill in */
  65.     }
  66.  
  67.      printf("| ") ;
  68.  
  69.      for( i=0 ; i < nbytes ; i = i+1 )    /* display ASCII form */
  70.     {  disp_char( tochar(block[i]) ) ; }
  71.      putchar('\n') ;
  72.   }
  73.  
  74. int  disp_char(c)            /* display one char in ASCII */
  75.   int    c ;                /* value of char to display  */
  76.   {
  77.      /* classify the character and handle accordingly  */
  78.  
  79.      if( isgraphic(c) )     /* ASCII graphic - display it */
  80.     ;
  81.      else if( c == '\n' )       /* newline (lf) - display symbol  */
  82.     c = PRT_LF ;
  83.      else if( c == '\r' )       /* Carr. Return - display symbol  */
  84.     c = PRT_CR ;
  85.      else if( c == ASC_CTLZ )    /* CTL-Z - display symbol */
  86.     c = PRT_CTLZ ;
  87.      else c = PRT_OTHER ;    /* other char - display symbol */
  88.  
  89.      putchar(c) ;
  90.   }
  91.  
  92.  
  93.  
  94.  
  95.